﻿/*
 * @Autor: PK
 * @Date: 2021/12/30 20:06:SS
 */

using System.Drawing;
using System.Windows.Forms;
using GMap.NET;
using GMap.NET.WindowsForms.Markers;
using ShkSimulation.carsharing.impl.elements;

namespace ShkSimulation.desktop.component.tools {

	public class AgencyMarker : GMarkerGoogle {

		private ToolTip toolTip;
		private readonly Station station;
		
		public double Longitude {
			get {
				return station.Longitude;
			}
			set {
				station.Longitude = value;
			}
		}

		public double Latitude {
			get {
				return station.Latitude;
			}
			set {
				station.Latitude = value;
			}
		}
		
		private AgencyMarker(Station station, PointLatLng pos, Bitmap bitmap) : base(pos, bitmap) {
			this.station = station;
			toolTip = new ToolTip();
			toolTip.ToolTipTitle = station.Name;
			toolTip.AutomaticDelay = 500;
			toolTip.ShowAlways = false;
			toolTip.AutoPopDelay = 5000;
			toolTip.ReshowDelay = 500;
			toolTip.InitialDelay = 500;
			toolTip.IsBalloon = false;
			this.Offset = new Point(this.Offset.X, this.Offset.Y + (int)(this.Size.Height / 2.0));
		}

		public static AgencyMarker Create(Station station, Bitmap context) {
			int width = 69, height = (int)(width * (1.0 * context.Height / context.Width));
			Bitmap bitmap = new Bitmap(context, new Size(width, height));
			PointLatLng pointLatLng = new PointLatLng(station.Latitude, station.Longitude);
			return new AgencyMarker(station, pointLatLng, bitmap);
		}

		public void ShowToolTip() {
			toolTip.SetToolTip(this.Overlay.Control, station.ToString());
		}

	}

}